import { UserProfilesAPI } from "@/Request/api"
export default {
  namespaced: true,
  state: {
    // 购物车数量
    cartTotal: 0,
    // 用户信息
    userInfo: {
      nickName: "用户昵称",
      coin: 1000,
      headImg: require("../../assets/img/service.848ec511.png")
    }
  },
  mutations: {
    updateUserInfo(state, payload) {
      // 修改用户信息的方法
      state.cartTotal = payload.cartTotal;
      state.userInfo = payload.userInfo
    },
    initUserInfo(state) {
      // 购物车数量
      state.cartTotal = 0,
        // 用户信息
        state.userInfo = {
          // 昵称
          nickName: '昵称',
          // 积分
          coin: 10000,
          // 用户头像
          headImg: require("../../assets/img/service.848ec511.png")
        }
    }
  },


  actions: {
    async asyncChangeUserInfo({ commit }, payload) {
      let res = await UserProfilesAPI();
      console.log("用户信息为:", res);
      commit('updateUserInfo', res.data)
    }
  }

}